from random import randint
import asyncio
import time

async def get_html(url):
    t = randint(1, 3)
    await asyncio.sleep(t)
    return f"get {url} spent {t}s"

def callback(future):
    print(future.result())

if __name__ == '__main__':  
    loop = asyncio.get_event_loop()
    tasklist = []
    start = time.time()
    for i in range(10):
        url = 'http://{}.com'.format(i)
        task = asyncio.ensure_future(get_html(url))
        task.add_done_callback(callback)
        tasklist.append(task)
    loop.run_until_complete(asyncio.gather(*tasklist))
    print("total spent {0}s".format(time.time()-start))
